package com.group3.merchant.servlet;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.group3.entity.Dish;
import com.group3.merchant.service.IDishService;
import com.group3.merchant.service.impl.DishServiceImpl;
import com.group3.merchant.utils.SenderUtil;

/**
 * Servlet implementation class DeleteDishServlet
 */
public class DeleteDishServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private IDishService service = new DishServiceImpl();
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteDishServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		deleteDish(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		deleteDish(request, response);
		//转发重定向
//		response.sendRedirect("ListDishServlet");
	}
	
	private void deleteDish(HttpServletRequest request, HttpServletResponse response) throws IOException {
		// TODO Auto-generated method stub
		String dId=request.getParameter("dId");
		//调service
		Dish dish = new Dish();
		dish.setdId(dId);
		
		int lines = service.delDish(dish);
		System.out.println(lines);
		if(lines>0){
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("result",lines);
			SenderUtil.send(map, response);
//		response.sendRedirect("ListDishServlet");
		}
		else {
			System.out.println("删除失败");
			
		}
	}

}
